let or = new Vue({
    el: '#order-list',
    data: {
        orders: [],
        isShow: false,
        currentPage: '',
        totalPageCount:''
    },
    created() {
        $.get('http://localhost:8080/cinema/api/OrderListServlet.do', function (dto) {
            or.orders = dto.value;
        });
    },
    methods: {
        checkPager: function () {
            let btn = $("#check");
            if (btn.text() == "分页显示") {
                // 分页查询
                $.get('http://localhost:8080/cinema/api/OrderListByPagerServlet.do', function (dto) {
                    or.orders = dto.value.data;
                    or.isShow = true;
                    or.currentPage = dto.value.currentPage;
                    btn.text('显示全部');    

                    if (dto.value.totalRecords % dto.value.pageCount == 0) {
                        or.totalPageCount = Math.floor(dto.value.totalRecords / dto.value.pageCount);
                      
                    } else {
                        or.totalPageCount = Math.floor(dto.value.totalRecords / dto.value.pageCount)+1;
                       
                    }

                });
            } else {
                // 非分页查询
                $.get('http://localhost:8080/cinema/api/OrderListServlet.do', function (dto) {
                    or.orders = dto.value;
                    or.isShow = false;
                    btn.text('分页显示');
                });
            }
        },
        first: function () {
            this.currentPage=1;
            let formData = {
                cp: this.currentPage
            }
            $.get('http://localhost:8080/cinema/api/OrderListByPagerServlet.do', formData,function (dto) {
                or.orders = dto.value.data;
            
            });
        },
        up: function () {
            if(this.currentPage==1){
                return;
            }
            this.currentPage=this.currentPage-1;
            let formData = {
                cp:this.currentPage
            }
            $.get('http://localhost:8080/cinema/api/OrderListByPagerServlet.do', formData,function (dto) {
                or.orders = dto.value.data;
               
            });
        },
        down: function () {
            if(this.currentPage==this.totalPageCount){
                return;
            }
            this.currentPage=this.currentPage+1;
            let formData = {
                cp: this.currentPage
            }
            $.get('http://localhost:8080/cinema/api/OrderListByPagerServlet.do', formData,function (dto) {
                or.orders = dto.value.data;
        
            });
        },
        end: function () {
            let formData = {
                cp:this.totalPageCount
            }
            $.get('http://localhost:8080/cinema/api/OrderListByPagerServlet.do', formData,function (dto) {
                or.orders = dto.value.data;
                or.currentPage = dto.value.currentPage;
            });
        },
        go:function(){
            let formData={
                cp:$(".bb").val()
            }
            
            $.get('http://localhost:8080/cinema/api/OrderListByPagerServlet.do', formData,function (dto) {
                or.orders = dto.value.data;
                or.currentPage = dto.value.currentPage;
            });
        },
        selectByLike:function(){
            
            let formData={
                cond:$("#cond").val()
            }
            // 发送异步 ，实现影片的模糊查询
            $.get('http://localhost:8080/cinema/api/SelectOrdersByLikeServlet.do',formData,function(dto){
                or.orders=dto.value;
            });
        },
        selectByLike2:function(){
            
            let formData={
                cond:$("#date").val()
            }
            // 发送异步 ，实现影片的模糊查询
            $.get('http://localhost:8080/cinema/api/SelectOrdersByLikeServlet.do',formData,function(dto){
                or.orders=dto.value;
            });
        }

    }
});